var i = require("../../../../common/vendor.js"), e = require("../../../uv-ui-tools/libs/mixin/mpMixin.js"), t = require("../../../uv-ui-tools/libs/mixin/mixin.js"), o = require("./props.js");

require("../../../uv-ui-tools/libs/function/index.js"), require("../../../uv-ui-tools/libs/function/test.js"), 
require("../../../uv-ui-tools/libs/function/digit.js"), require("../../../uv-ui-tools/libs/util/route.js"), 
require("../../../uv-ui-tools/libs/function/debounce.js"), require("../../../uv-ui-tools/libs/function/throttle.js");

var r = {
    name: "uv-image",
    emits: [ "click", "load", "error" ],
    mixins: [ e.mpMixin, t.mixin, o.props ],
    data: function() {
        return {
            isError: !1,
            loading: !0,
            backgroundStyle: {},
            show: !1,
            observeShow: !this.observeLazyLoad,
            elIndex: "",
            imgWidth: this.width,
            imgHeight: this.height,
            thresholdValue: 50
        };
    },
    watch: {
        src: {
            immediate: !0,
            handler: function(i) {
                i ? (this.isError = !1, this.loading = !0) : this.isError = !0;
            }
        },
        width: function(i) {
            var e = this;
            this.show = !1, this.$uv.sleep(2).then(function(i) {
                e.show = !0;
            }), this.imgWidth = i;
        },
        height: function(i) {
            var e = this;
            this.show = !1, this.$uv.sleep(2).then(function(i) {
                e.show = !0;
            }), this.imgHeight = i;
        }
    },
    computed: {
        wrapStyle: function() {
            var i = {};
            return "heightFix" !== this.mode && (i.width = this.$uv.addUnit(this.imgWidth)), 
            "widthFix" !== this.mode && (i.height = this.$uv.addUnit(this.imgHeight)), i.borderRadius = "circle" == this.shape ? "10000px" : this.$uv.addUnit(this.radius), 
            i.overflow = this.radius > 0 ? "hidden" : "visible", this.$uv.deepMerge(i, this.$uv.addStyle(this.customStyle));
        },
        imageStyle: function() {
            var i = {};
            return i.borderRadius = "circle" == this.shape ? "10000px" : this.$uv.addUnit(this.radius), 
            i;
        }
    },
    created: function() {
        this.elIndex = this.$uv.guid(), this.observer = {}, this.observerName = "lazyLoadContentObserver";
    },
    mounted: function() {
        var i = this;
        this.show = !0, this.$nextTick(function() {
            i.observeLazyLoad && i.observerFn();
        });
    },
    methods: {
        onClick: function() {
            this.$emit("click");
        },
        onErrorHandler: function(i) {
            this.loading = !1, this.isError = !0, this.$emit("error", i);
        },
        onLoadHandler: function(i) {
            "widthFix" == this.mode && (this.imgHeight = "auto"), "heightFix" == this.mode && (this.imgWidth = "auto"), 
            this.loading = !1, this.isError = !1, this.$emit("load", i), this.removeBgColor();
        },
        removeBgColor: function() {
            this.backgroundStyle = {
                backgroundColor: "transparent"
            };
        },
        observerFn: function() {
            var e = this;
            this.$nextTick(function() {
                i.index.$once("onLazyLoadReachBottom", function() {
                    e.observeShow || (e.observeShow = !0);
                });
            }), setTimeout(function() {
                e.disconnectObserver(e.observerName);
                var t = i.index.createIntersectionObserver(e);
                t.relativeToViewport({
                    bottom: e.thresholdValue
                }).observe(".uv-image--".concat(e.elIndex), function(i) {
                    i.intersectionRatio > 0 && (e.observeShow = !0, e.disconnectObserver(e.observerName));
                }), e[e.observerName] = t;
            }, 50);
        },
        disconnectObserver: function(i) {
            var e = this[i];
            e && e.disconnect();
        }
    }
};

Array || (i.resolveComponent("uv-icon") + i.resolveComponent("uv-transition"))(), 
Math || (function() {
    return "../../../uv-icon/components/uv-icon/uv-icon.js";
} + function() {
    return "../../../uv-transition/components/uv-transition/uv-transition.js";
})();

var n = i._export_sfc(r, [ [ "render", function(e, t, o, r, n, s) {
    return i.e({
        a: n.show
    }, n.show ? i.e({
        b: !n.isError && n.observeShow
    }, !n.isError && n.observeShow ? {
        c: e.src,
        d: e.mode,
        e: i.o(function() {
            return s.onErrorHandler && s.onErrorHandler.apply(s, arguments);
        }),
        f: i.o(function() {
            return s.onLoadHandler && s.onLoadHandler.apply(s, arguments);
        }),
        g: e.showMenuByLongpress,
        h: e.lazyLoad,
        i: i.s(s.imageStyle),
        j: e.webp
    } : {}, {
        k: e.showLoading && n.loading
    }, e.showLoading && n.loading ? {
        l: i.p({
            name: e.loadingIcon,
            width: e.width,
            height: e.height
        }),
        m: "circle" == e.shape ? "50%" : e.$uv.addUnit(e.radius),
        n: e.bgColor,
        o: e.$uv.addUnit(e.width),
        p: e.$uv.addUnit(e.height)
    } : {}, {
        q: e.showError && n.isError && !n.loading
    }, e.showError && n.isError && !n.loading ? {
        r: i.p({
            name: e.errorIcon,
            width: e.width,
            height: e.height
        }),
        s: "circle" == e.shape ? "50%" : e.$uv.addUnit(e.radius),
        t: e.$uv.addUnit(e.width),
        v: e.$uv.addUnit(e.height)
    } : {}, {
        w: i.n("uv-image--".concat(n.elIndex)),
        x: i.o(function() {
            return s.onClick && s.onClick.apply(s, arguments);
        }),
        y: i.s(s.wrapStyle),
        z: i.s(n.backgroundStyle),
        A: i.p({
            show: n.show,
            mode: "fade",
            duration: e.fade ? e.duration : 0,
            "cell-child": e.cellChild,
            "custom-style": s.wrapStyle
        })
    }) : {});
} ], [ "__scopeId", "data-v-22515f73" ] ]);

wx.createComponent(n);